<?php
/**
 * Created by gumaor.com
 * User: tommy
 */

namespace app\v1\controller;


use lib\jwt\Token;
use Timo\Core\Application;
use Timo\Core\Request;
use Timo\Core\Response;

class Base
{
    public static $u;

    public function __construct()
    {
        self::checkToken();
    }

    /**
     * 验证TOKEN有效性
     *
     * @return bool
     */
    private static function checkToken()
    {
        $token = Request::getHeaders('Token');
        if (is_null($token)) {
            Response::send(Application::result(403, 'user invalid'));
        }

        $uid = Token::validateToken($token);
        if (!$uid) {
            Response::send(Application::result(403, 'token expire'));
        }
        Base::$u = ['uid' => $uid];
        return true;
    }
}
